package com.cwd.arm.inter.util;

import com.cwd.arm.application.dto.ProjectDto;
import com.cwd.arm.application.dto.confirmIncome.ConfirmIncomeMonthAmountDto;
import com.cwd.arm.application.dto.confirmIncome.ProjectConfirmIncomeDto;
import com.cwd.arm.application.dto.project.*;
import com.cwd.arm.common.util.BeanUtil;
import com.cwd.arm.inter.vo.ResponseVo;

import java.util.*;

/**
 * Created by yan on 22-2-4.
 */
public class DtoToMapUtil<T> {

    public Map<String, Object> getMap(List<T> dtoList) {
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> projectList = new ArrayList<>();
        for (int i=0;i<dtoList.size();i++) {
            Map<String, Object> projectMap = BeanUtil.entityToMap(dtoList.get(i));
            projectMap.put("no",i+1);
            projectList.add(projectMap);
        }
        map.put("projectList", projectList);
        return map;
    }

//    public static Map<String, Object> getProjectMap(List<ProjectDto> dtoList) {
//        Map<String, Object> map = new HashMap<>();
//        List<Map<String, Object>> projectList = new ArrayList<>();
//        for (int i=0;i<dtoList.size();i++) {
//            Map<String, Object> projectMap = BeanUtil.entityToMap(dtoList.get(i));
//            projectMap.put("no",i+1);
//            projectList.add(projectMap);
//        }
//        map.put("projectList", projectList);
//        return map;
//    }

    public static Map<String, Object> getCashExcelMap(List<ProjectCashFlowDto> dtoList, CashFlowTotalDto totalDto) {
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> projectList = new ArrayList<>();
        int no = 1;
        for (ProjectCashFlowDto dto : dtoList) {
            Map<String, Object> projectMap = new HashMap<>();
            projectMap.put("no", no);
            projectMap.put("projectName", dto.getProjectName());
            projectMap.put("closeAmount", dto.getCloseAmount());
            projectMap.put("contractAmount", dto.getContractAmount());
            projectMap.put("withLastReceivedAmount", dto.getWithLastReceivedAmount());
            projectMap.put("withLastYearActualPayAmount", dto.getWithLastYearActualPayAmount());
            projectMap.put("fyCashAmount", dto.getFyCashAmount());
            projectMap.put("fyActualPayAmount", dto.getFyActualPayAmount());
            projectMap.put("fyReceivedAmount", dto.getFyReceivedAmount());
            List<ProjectCashFlowMonthDto> projectMonthDtoList = dto.getCashFlowMonthDtoList();
            for (ProjectCashFlowMonthDto monthDto : projectMonthDtoList) {
                setCashMonthInfo(projectMap, monthDto);
            }
            projectList.add(projectMap);
            no++;
        }
        map.put("projectList", projectList);
        map.put("fyCashAmount", totalDto.getFyCashAmount());
        map.put("fyActualPayAmount", totalDto.getFyActualPayAmount());
        map.put("fyReceivedAmount", totalDto.getFyReceivedAmount());
        List<CashFlowMonthDto> totalMonthList = totalDto.getCashFlowMonthDtoList();
        for (CashFlowMonthDto monthDto : totalMonthList) {
            setCashMonthInfo(map, monthDto);
        }
        return map;
    }

    public static Map<String, Object> getReceivableAmountExcelMap(List<ProjectReceivableAmountDto> dtoList, ProjectReceivableAmountTotalDto totalDto) {
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> projectList = new ArrayList<>();
        int no = 1;
        for (ProjectReceivableAmountDto dto : dtoList) {
            Map<String, Object> projectMap = new HashMap<>();
            projectMap.put("no", no);
            projectMap.put("projectStatus", dto.getProjectStatus());
            projectMap.put("projectType", dto.getProjectTypeKey());
            projectMap.put("projectName", dto.getProjectName());
            projectMap.put("partnerName", dto.getPartnerName());
            projectMap.put("contractAmount", dto.getContractAmount());
            projectMap.put("taxConfirmAmount", dto.getTaxConfirmAmount());
            projectMap.put("receivedAmount", dto.getReceivedAmount());
            projectMap.put("receivableAmount", dto.getReceivableAmount());
            projectMap.put("nextWeekRate", dto.getNextWeekRate());
            projectMap.put("nextWeekNodeCondition", dto.getNextWeekNodeCondition());
            projectMap.put("nextWeekEndDate", dto.getNextWeekEndDate());
            projectMap.put("nextWeekReceivableAmount", dto.getNextWeekReceivableAmount());
            projectMap.put("thisFyQ1Amount", dto.getThisFyQ1Amount());
            projectMap.put("thisFyQ2Amount", dto.getThisFyQ2Amount());
            projectMap.put("thisFyQ3Amount", dto.getThisFyQ3Amount());
            projectMap.put("thisFyQ4Amount", dto.getThisFyQ4Amount());
            projectMap.put("thisFyTotalAmount", dto.getThisFyTotalAmount());
            projectMap.put("lastFyTotalAmount", dto.getLastFyTotalAmount());
            projectMap.put("dataDirector", dto.getDataDirector());
            projectMap.put("isBadDebt", dto.getIsBadDebt());
            projectMap.put("remark", dto.getRemark());
            projectList.add(projectMap);
            no++;
        }
        map.put("projectList", projectList);
        map.put("contractAmount", totalDto.getContractAmount());
        map.put("taxConfirmAmount", totalDto.getTaxConfirmAmount());
        map.put("receivedAmount", totalDto.getReceivedAmount());
        map.put("receivableAmount", totalDto.getReceivableAmount());
        map.put("thisFyQ1Amount", totalDto.getThisFyQ1Amount());
        map.put("thisFyQ2Amount", totalDto.getThisFyQ2Amount());
        map.put("thisFyQ3Amount", totalDto.getThisFyQ3Amount());
        map.put("thisFyQ4Amount", totalDto.getThisFyQ4Amount());
        map.put("thisFyTotalAmount", totalDto.getThisFyTotalAmount());
        map.put("lastFyTotalAmount", totalDto.getLastFyTotalAmount());
        map.put("exportDate", new Date());
        return map;
    }

    public static Map<String, Object> getConfirmIncomeMap(List<ProjectConfirmIncomeDto> dtoList) {
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> projectList = new ArrayList<>();
        int no = 1;
        for (ProjectConfirmIncomeDto dto : dtoList) {
            Map<String, Object> projectMap = new HashMap<>();
            projectMap.put("no", no);
            projectMap.put("dataDirector", dto.getDataDirector());
            projectMap.put("projectName", dto.getProjectName());
            projectMap.put("projectType", dto.getProjectTypeKey());
            projectMap.put("contractAmount", dto.getContractAmount());
            projectMap.put("closeAmount",dto.getCloseAmount());
            projectMap.put("remark", dto.getRemark());
            projectMap.put("fyTaxTargetAmount", dto.getFyTaxTargetAmount());
            projectMap.put("fyTargetAmount", dto.getFyTargetAmount());
            projectMap.put("fyTargetRate", dto.getFyTargetRate());
            projectMap.put("rtTaxAmount", dto.getRtTaxAmount());
            projectMap.put("rtRate", dto.getRtRate());
            projectMap.put("rtAmount", dto.getRtAmount());
            projectMap.put("surplusTaxAmount", dto.getSurplusTaxAmount());
            projectMap.put("surplusAmount", dto.getSurplusAmount());
            List<ConfirmIncomeMonthAmountDto> monthAmountDtoList = dto.getMonthAmountDtoList();
            for (ConfirmIncomeMonthAmountDto monthDto : monthAmountDtoList) {
                projectMap.put("rate" + monthDto.getMonth(), monthDto.getRate());
                projectMap.put("amount" + monthDto.getMonth(), monthDto.getAmount());
            }
            projectList.add(projectMap);
            no++;
        }
        map.put("projectList", projectList);
        return map;
    }

    private static void setCashMonthInfo(Map<String, Object> map, CashFlowMonthDto monthDto) {
        map.put("receivedAmount" + monthDto.getMonth(), monthDto.getReceivedAmount());
        map.put("actualPayAmount" + monthDto.getMonth(), monthDto.getActualPayAmount());
        map.put("cashFlowAmount" + monthDto.getMonth(), monthDto.getCashFlowAmount());
    }

    public static <E> DtoToMapUtil<E> BUILDER() {
        return new DtoToMapUtil();
    }
}
